package com.czl.module_storehouse.mvp.model;

import com.czl.base.config.AppConstants;
import com.czl.base.util.SpHelper;
import com.czl.module_base.mvp.model.BaseModel;
import com.czl.module_service.system.Constants;
import com.google.gson.Gson;

import org.json.JSONObject;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @author by xubin,
 * @date on 2022/2/18.
 * PS: Not easy to write code, please indicate.
 */
public class BasicDataModel extends BaseModel {

    protected String getUserId() {
        return SpHelper.INSTANCE.decodeString(Constants.SpKey.STOREHOUSE_USER_ID);
    }

    protected String getTName() {
        return SpHelper.INSTANCE.decodeString(Constants.SpKey.STOREHOUSE_USER_NAME);
    }

    protected int getManageCompanyId() {
        return SpHelper.INSTANCE.decodeInt(Constants.SpKey.MANAGE_COMPANY_ID);
    }

    protected int getStorehouseId() {
        return SpHelper.INSTANCE.decodeInt(Constants.SpKey.STOREHOUSE_ID);
    }

    protected int getStorehouseLocatId() {
        return SpHelper.INSTANCE.decodeInt(Constants.SpKey.STOREHOUSE_LOCATION_ID);
    }

    protected int getCompanyId() {
        return SpHelper.INSTANCE.decodeInt(Constants.SpKey.COMPANY_ID);
    }

    protected int getStorehouseLocationId() {
        return SpHelper.INSTANCE.decodeInt(Constants.SpKey.STOREHOUSE_LOCATION_ID);
    }

    protected String getManageCompanyName() {
        return SpHelper.INSTANCE.decodeString(Constants.SpKey.MANAGE_COMPANY_NAME);
    }

    protected String getManageCompanyShortName() {
        return SpHelper.INSTANCE.decodeString(Constants.SpKey.MANAGE_COMPANY_SHORT_NAME);
    }

    protected String getStoreCompanyShortName() {
        return SpHelper.INSTANCE.decodeString(Constants.SpKey.MANAGE_COMPANY_SHORT_NAME);
    }

    public RequestBody getRequestBodyByStorehouseIdPageNo(int pageNo) {
        JSONObject object = new JSONObject();
        try {
            object.put("storehouseId", getStorehouseId());
            object.put("pageNo", pageNo);
            object.put("pageSize", 10);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String json = object.toString();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RequestBody.create(mediaType, json);
    }

    public RequestBody createBody(JSONObject object) {
        String json = object.toString();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RequestBody.create(mediaType, json);
    }

    public RequestBody createBody(String json) {
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RequestBody.create(mediaType, json);
    }

    public RequestBody createBodyByPage(int pageNo) {
        JSONObject object = new JSONObject();
        try {
            object.put("companyId", "1");
            object.put("pageNo", pageNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String json = object.toString();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RequestBody.create(mediaType, json);
    }

    public RequestBody createBody(Object object) {
        String json = new Gson().toJson(object);
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        return RequestBody.create(mediaType, json);
    }
}
